﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Fashion.Models;

namespace Fashion.ViewModels
{
    public class ProductViewModel
    {
        private FashionEntities1 FashionDB = new FashionEntities1();

        public Product product;
        public ProductDetail detail;
        public List<string> Size;
        public List<int> SizeID;
        public List<string> Color;
        public List<int> ColorID;
        public List<string> Category;
        public List<int> CatID;
        public List<string> Brand;
        public List<int> BrandID;
        public List<string> SizeDetail;
        public List<int> ColorDetail;

        public ProductViewModel(int pid)
        {
            var product = FashionDB.Products.Single(p => p.ProductID == pid);
            this.product = product;

            var SizeModel = from size in FashionDB.Sizes
                            select size.Name;

            var SizeIDModel = from size in FashionDB.Sizes
                              select size.SizeID;

            Size = SizeModel.ToList();
            SizeID = SizeIDModel.ToList();

            var ColorModel = from color in FashionDB.Colors
                             select color.Name;

            var ColorIDModel = from color in FashionDB.Colors
                               select color.ColorID;

            Color = ColorModel.ToList();
            ColorID = ColorIDModel.ToList();

            var CategoryModel = from cat in FashionDB.Categories
                                select cat.Name;
            var CatIDModel = from cat in FashionDB.Categories
                             select cat.CategoryID;
            Category = CategoryModel.ToList();
            CatID = CatIDModel.ToList();

            var BrandModel = from brand in FashionDB.Brands
                             select brand.BrandName;

            var BrandIDModel = from brand in FashionDB.Brands
                               select brand.BrandID;
            Brand = BrandModel.ToList();
            BrandID = BrandIDModel.ToList();

            var sizeDetail = (from detail in FashionDB.ProductDetails
                              where detail.ProductID == pid
                              select detail.SizeList).First();
            string[] temp = sizeDetail.Split(';');
            SizeDetail = new List<string>(temp);

            var colorDetail = from detail in FashionDB.ProductDetails
                              where detail.ProductID == pid
                              select detail.ColorID;
            ColorDetail = colorDetail.ToList();
        }

    }
}
